<html>
<head>
<title>Equipment</title>
<?php include 'sethead.php'; ?>
<script>
    $(document).ready(function() {
        // Set Loading
        $("#spinner").bind("ajaxSend", function() {
            $(this).show();
        }).bind("ajaxStop", function() {
            $(this).hide();
        }).bind("ajaxError", function() {
            $(this).hide();
        });
        
        function selectBrand(){ 
            $("#drpBrand").find('option').remove();
            $("#drpBrand").append(new Option("---Select---",""));
            $.getJSON("select.php?select=brand",{
                    table : "brand" 
                },
                function(data){
                    for(var i=0;i<data.length;i++){
                        $("#drpBrand").append(new Option(data[i].Brand,data[i].BrandId));
                    }
                }
            );
        }
        function selectLocation(){
            $("#drpLocation").find('option').remove();
            $("#drpLocation").append(new Option("---Select---",""));
             $.getJSON("select.php?select=location",{
                    table : "location" 
                },
                function(data){
                    //alert(data);
                    for(var i=0;i<data.length;i++){
                        $("#drpLocation").append(new Option(data[i].Location,data[i].LocationId));
                    }
                }
            );
        }
        function selectJob(){
            $("#drpJob").find('option').remove();
            $("#drpJob").append(new Option("---Select---",""));
             $.getJSON("select.php?select=job",{
                    table : "job" 
                },
                function(data){
                    //alert(data);
                    for(var i=0;i<data.length;i++){
                        $("#drpJob").append(new Option(data[i].Job,data[i].JobId));
                    }
                }
            );
        }
        function selectSupplier(){
            $("#drpSupplier").find('option').remove();
            $("#drpSupplier").append(new Option("---Select---",""));
             $.getJSON("select.php?select=supplier",{
                    table : "supplier" 
                },
                function(data){
                    //alert(data);
                    for(var i=0;i<data.length;i++){
                        $("#drpSupplier").append(new Option(data[i].SupplierName,data[i].SupplierCode));
                    }
                }
            );
        }
        
        selectBrand();
        selectJob();
        selectLocation();
        selectSupplier();
        $( "#menu_equipment" ).addClass("active");
        $("#aBrand").click(function (){
            $.fancybox({
                autoSize : false,
                'width'			: '460',
                'height'		: '200',
                'autoScale'		: false,
                'type'			: 'iframe',
                'href'			: 'frmAddBrand.php',// หน้าที่ต้องการจะให้บ๊อปอัพขึ้นมา
                afterClose : function(){ selectBrand(); }
            });
        });
        $("#aLocation").click(function (){
            $.fancybox({
                autoSize : false,
                'width'			: '460',
                'height'		: '200',
                'autoScale'		: false,
                'type'			: 'iframe',
                'href'			: 'frmAddLocation.php',// หน้าที่ต้องการจะให้บ๊อปอัพขึ้นมา
                afterClose : function(){ selectLocation(); }
            });
        });
        $("#aJob").click(function (){
            $.fancybox({
                autoSize : false,
                'width'			: '460',
                'height'		: '200',
                'autoScale'		: false,
                'type'			: 'iframe',
                'href'			: 'frmAddJob.php',// หน้าที่ต้องการจะให้บ๊อปอัพขึ้นมา
                afterClose : function(){ selectJob(); }
            });
        });
        $("#aSupplier").click(function (){
            $.fancybox({
                autoSize : false,
                'width'			: '460',
                'height'		: '350',
                'autoScale'		: false,
                'type'			: 'iframe',
                'href'			: 'frmAddSupplier.php',// หน้าที่ต้องการจะให้บ๊อปอัพขึ้นมา
                afterClose : function(){ selectSupplier(); }
            });
        });
        $("#btClear").click(function(){
            $("#txtCodeNo").val("");
            $("#txtChassis").val("");
            $("#txtEngineModel").val("");
            $("#txtEngineNo").val("");
            $("#txtDescription").val("");
            $("#drpBrand").val("");
            $("#txtModel").val("");
            $("#txtHP").val("");
            $("#txtWorkOrder").val("");
            $("#drpLocation").val("");
            $("#drpJob").val("");
            $("#drpSupplier").val("");
            $("#txtMileage").val("");
            $("#txtRemark").val("");
        });
        $("#btSubmit").click(function(){
            if($("#txtCodeNo").val()==""){
                $.Zebra_Dialog('Please input Code No',{
                    'type':'warning',
                    'title':'Warning',
                    onClose:function(){
                        $("#txtCodeNo").focus();
                    }
                });
                return false;
            }
            if($("#txtChassis").val()==""){
                $.Zebra_Dialog('Please input Chassis',{
                    'type':'warning',
                    'title':'Warning',
                    onClose:function(){
                        $("#txtChassis").focus();
                    }
                });
                return false;
            }
            if($("#txtDescription").val()==""){
                $.Zebra_Dialog('Please input Description',{
                    'type':'warning',
                    'title':'Warning',
                    onClose:function(){
                        $("#txtDescription").focus();
                    }
                });
                return false;
            }
            if($("#drpBrand").val()==""){
                $.Zebra_Dialog('Please input Brand',{
                    'type':'warning',
                    'title':'Warning',
                    onClose:function(){
                        $("#drpBrand").focus();
                    }
                });
                return false;
            }
            if($("#drpLocation").val()==""){
                $.Zebra_Dialog('Please input Location',{
                    'type':'warning',
                    'title':'Warning',
                    onClose:function(){
                        $("#drpLocation").focus();
                    }
                });
                return false;
            }
            if($("#drpJob").val()==""){
                $.Zebra_Dialog('Please select Job',{
                    'type':'warning',
                    'title':'Warning',
                    onClose:function(){
                        $("#frpJob").focus();
                    }
                });
                return false;
            }
            if($("#drpSupplier").val()==""){
                $.Zebra_Dialog('Please select Supplier',{
                    'type':'warning',
                    'title':'Warning',
                    onClose:function(){
                        $("#drpSupplier").focus();
                    }
                });
                return false;
            }
            //alert($( "input:radio[name=rdoReading]:checked" ).val());
            $('#spinner').show();
            $.post(
                "conEquipment.php",
                {
                    txtCodeNo: $("#txtCodeNo").val(),
                    txtChassis: $("#txtChassis").val(),
                    txtEngineModel: $("#txtEngineModel").val(),
                    txtEngineNo: $("#txtEngineNo").val(),
                    txtDescription: $("#txtDescription").val(),
                    drpBrand: $("#drpBrand").val(),
                    txtModel: $("#txtModel").val(),
                    txtHP: $("#txtHP").val(),
                    txtWorkOrder: $("#txtWorkOrder").val(),
                    drpLocation: $("#drpLocation").val(),
                    drpJob: $("#drpJob").val(),
                    drpSupplier: $("#drpSupplier").val(),
                    rdoReading: $("input:radio[name=rdoReading]:checked" ).val() ,
                    txtMileage: $("#txtMileage").val(),
                    txtRemark: $("#txtRemark").val()
                },
                function(data){
                    $('#spinner').hide();
                    alert(data);
                    if(data == "success"){
                        $.Zebra_Dialog('Insert Success',{'type':'confirmation','title':'Succress'});
                    }else if(data == "duplicate"){
                        $.Zebra_Dialog('SupplierCode is Duplicate',{'type':'warning','title':'Duplicate'});
                    }else{
                        $.Zebra_Dialog('Insert Error',{'type':'error','title':'Error'});
                    }
                }
            ); 
             
        });
    });
</script>
</head>
<body id="Body_Equipment">
<div class='main'>
<?php include 'menu.php' ?>
    <div class='headpage'>
        Equipment
    </div>
    <table border="0" >
        <tr>
          <td class="right"> 
              ITD Asset Code : <br> <font size=2>(Code No.)&nbsp;&nbsp;&nbsp;<font>
          </td>
          <td class="left">
              <input name="txtITDAsset" type="text" id="txtCodeNo" class='input-m' tabindex="1">
          </td>
          <td class="right">
              Chassis/Serial : 
          </td>
          <td class='left'>
              <input name="txtChassis" type="text" id="txtChassis" class='input-m' tabindex="2">
          </td>
        </tr>
        <tr>
          <td class='right'> 
              Engine Model : 
          </td>
          <td class='left'>
              <input name="txtEngineModel" type="text" id="txtEngineModel" class='input-m' tabindex="3">
          </td>
          <td class='right'> 
              Engine No. : 
          </td>
          <td class='left'>
              <input name="txtEngineNo" type="text" id="txtEngineNo" class='input-m' tabindex="4">
          </td>
        </tr>
        <tr>
          <td class='right'>
              Description : 
          </td>
          <td class='left'>
              <input name="txtDescription" type="text" id="txtDescription" class='input-m' tabindex="5">
          </td>
          <td class='right'>
              Brand : 
          </td>
          <td class='left'>
              <select data-placeholder="Choose a Country..." class="input-m" id="drpBrand" tabindex="6">
                    <option value="">---Select---</option>
                </select>
                <a href="#" class='add' id='aBrand'>Add</a>
          </td>
        </tr>
        <tr>
          <td class='right'>
              Model : 
          </td>
          <td class='left'>
              <input name="txtModel" type="text" id="txtModel" class='input-m' tabindex="7"> 
          </td>
          <td class='right'>
              HP : 
          </td>
          <td class='left'>
              <input type="text" id="txtHP" name="txtHP" class='input-m' tabindex="8"> 
          </td>
        </tr>
        <tr>
            <td class='right'>
                Work Order : 
            </td>
            <td class='left'>
                <input type='text' id='txtWorkOrder' name='txtWorkOrder' class='input-m' tabindex="9">
            </td>
            <td class='right'>
                Location : 
            </td>
            <td class='left'>
                <select data-placeholder="Choose a Country..." class="input-m" id="drpLocation" tabindex="10">
                    <option value="">---select---</option>
                </select>
                <a href="#" class='add' id='aLocation'>Add</a>
            </td>
        </tr>
        <tr>
          <td class='right'>
              Job : 
          </td>
          <td>
              <select data-placeholder="Choose..." class="input-s" id="drpJob" tabindex="11">
                    <option value="">---Select---</option>
              </select>
              <a href="#" class='add' id="aJob">Add</a>
          </td>
          <td class='right'>
              Supplier : 
          </td>
          <td class='left'>
              <select data-placeholder="Choose a Country..." class="input-m" id="drpSupplier" tabindex="12">
                    <option value="">---Select---</option>
                </select>
              <a href="#" class='add' id="aSupplier">Add</a>
          </td>
        </tr>
        <tr>
          <td class='right'>
              Reading : 
          </td>
          <td class='left'>
              <input type="radio" name="rdoReading" id="rdoKM" value="KM" checked="true" tabindex="13"/> <label for="rdoKM">KM</label>
              <input type="radio" name="rdoReading" id="rdoSMU" value="SMU" tabindex="14"/> <label for="rdoSMU">SMU</label>
          </td>
          <td class='right'>
              Mileage : 
          </td>
          <td class='lift'>
              <input type="text" id="txtMileage" name="txtMileage" class='input-m' tabindex="15">
          </td>
        </tr>
        <tr>
            <td class='right'>
                Remark : 
            </td>
            <td colspan="3" class='left'>
                <textarea id="txtRemark" cols="45" tabindex="16"></textarea>
            </td>
        </tr>
        <tr>
          <td class='center' colspan='4'>
              <button id="btSubmit" tabindex="17">Submit</button>
              <button id="btClear" tabindex="18">Clear</button>
          </td>
        </tr>
   </table>
  <br> 

</div>
<div class="footer">
    <?php
        include 'footer.php';
    ?>
</div>
</body> 
</html>